package cn.cvs.servlet.sysRole;

import cn.cvs.pojo.SysRole;
import cn.cvs.service.SysRoleService;
import cn.cvs.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ToUpdateRoleServlet", urlPatterns = "/sys/role/toUpdate")
public class ToUpdateRoleServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet ( request, response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding ( "utf-8" );
        response.setContentType ( "text/html;charset=UTF-8" );
        SysRoleService sysRoleService= (SysRoleService) SpringUtil.getBean ( "sysRoleService" );
        String roleId = request.getParameter ( "roleId" );
        SysRole sysRole = sysRoleService.getSysRoleById ( Integer.valueOf ( roleId ) );
        request.setAttribute ( "sysRole", sysRole );
        request.getRequestDispatcher ( "/WEB-INF/jsp/sysRole/update.jsp" ).forward ( request, response );
    }
}
